package itxinhaimijijia.hierarchicaldecoupling.service.impl;

import itxinhaimijijia.hierarchicaldecoupling.dao.HeroDao;
import itxinhaimijijia.hierarchicaldecoupling.dao.Impl.HeroDaoImpl;
import itxinhaimijijia.hierarchicaldecoupling.projo.Hero;
import itxinhaimijijia.hierarchicaldecoupling.service.HeroService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

//@Component
public class HeroServicImpl implements HeroService {

    public HeroDao heroDao = new HeroDaoImpl();

    @Override
    public List<Hero> findAll() {
//        return List.of();

        List<String> linesDao = heroDao.findAll();
        List<Hero> list = linesDao.stream().map(item -> {
            String[] split = item.split(",");
            Integer id = Integer.parseInt(split[0]);
            String name = split[1];
            String password = split[2];
            String nickname = split[3];
            Integer age = Integer.parseInt(split[4]);
            LocalDateTime updateTime = LocalDateTime.parse(split[5], DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
            return new Hero(id, name, password, nickname, age, updateTime);
        }).toList();

        return list;

    }
}
